package com.yzk.train.member.controller;

import com.yzk.train.common.context.MemberLoginContext;
import com.yzk.train.common.response.PageResp;
import com.yzk.train.common.response.Result;
import com.yzk.train.member.request.PassengerQueryReq;
import com.yzk.train.member.request.PassengerSaveReq;
import com.yzk.train.member.response.PassengerQueryResp;
import com.yzk.train.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Resource
    private PassengerService passengerService;

    @PostMapping("/save")
    public Result<String> save(@Valid @RequestBody PassengerSaveReq req) {
        String message = passengerService.save(req);
        return Result.ok(message);
    }

    @GetMapping("/list")
    public Result<PageResp<PassengerQueryResp>> queryList(@Valid PassengerQueryReq req) {
        req.setMemberId(MemberLoginContext.getId());
        PageResp<PassengerQueryResp> pageResp = passengerService.queryList(req);
        return Result.ok(pageResp);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> edit(@PathVariable Long id) {
        passengerService.delete(id);
        return Result.ok("删除成功");
    }

    @GetMapping("/query-mine")
    public Result<List<PassengerQueryResp>> queryMine() {
        List<PassengerQueryResp> list = passengerService.queryMine();
        return Result.ok(list);
    }

}
